<!--{template lyear:header_simple_start}-->
<link href="{MOD_PATH}/images/market.css?{VERHASH}" rel="stylesheet" media="all">
<style>
.card-market .upgrade_progess{
	position: absolute;
	bottom:0;
	left: 0;
	width:0%;
	height: 10%;
}
</style>
<!--{template lyear:header_simple_end}-->
<main class="bs-main-container">
	<div class="container-fluid">
	  <div class="card">
		<header class="card-header flex-container">
			<a href="{MOD_URL}" class="dcolor">{lang total}<span class="num">$total</span>{lang ge}{lang app}</a>
		</header>
		<div class="card-body">
			<div class="alert alert-warning" role="alert">
				{lang manual_install_tip}
			</div>
		<!--{if $list}-->
		<div class="d-flex flex-wrap mb-3 justify-content-center">
			<!--{loop $list $value}-->
			<div class="card card-market m-2" style="width:18rem;">
				<div class="card-image color-block-{$value[cover_color]}">
					<div id="progess_{$value[mid]}">
						<div class="progress-bar upgrade_progess" role="progressbar" id="upgrade_progess_{$value[mid]}"></div>
						</div>
					<a href="javascript:;" data-href="{$cloudurl}?mod=dzzmarket&op=ajax&do=view&mid=$value[mid]&refer=$refer" class="view-detail" title="$value[name]"><img src="$value[coverimg]" alt="$value[name]" /></a>
				</div>
				<div class="card-body">
					<h5 class="card-title"><a href="javascript:;" data-href="{$cloudurl}?mod=dzzmarket&op=ajax&do=view&mid=$value[mid]&refer=$refer" target="_blank" class="dcolor view-detail text-truncate" title="$value[name]">$value[name]</a><span class="badge rounded-pill bg-success" title="最新版本：$value[version]">V&nbsp;$value[version]</span></h5>
					<p class="card-text text-truncate">{eval echo $value['desc_short']?$value['desc_short']:lang('none');}</p>
				</div>
				<ul class="list-group list-group-flush">
					<li class="list-group-item"><i class="mdi mdi-tag"></i> 应用分类：{$value['classid_name']}</li>
					<li class="list-group-item"><i class="mdi mdi-account"></i> 开发者：$value[vendor]</li>
					<li class="list-group-item"><i class="mdi mdi-download"></i> {lang big_small}：{eval echo formatsize($value['packagesize']);}</li>
				</ul>
				<div class="card-body d-grid">
					<!--{if $value[price]>0}-->
					<button class="btn btn-round btn-danger btn-sm"  onclick="showBuyInfo(this,'$value[mid]')" data-href="$cloudurl?mod=dzzmarket&op=ajax&do=getBuyInfo&mid=$value[mid]" title="{lang buy_contract}">{lang buy}</button>
					<!--{else}-->
						<!--{if $value[package]}--> 
							<!--{if $value["local_appinfo"]}-->
							<button class="btn btn-round btn-secondary btn-sm" disabled data-mid="$value['mid']" title="{lang installed}">
							{lang installed}
							</button>
							<!--{else}-->
							<button class="btn btn-round btn-primary btn-sm" style="white-space: inherit;" onclick="start_check_install('{MOD_URL}&op=install_app_ajax&operation=check_install&appid=$value[identifier]','{$value[mid]}','{$value[baseinfo]}');" id="upgrade_info_{$value[mid]}">{lang install_onekey}</button>
							<!--{/if}--> 
						<!--{else}--> 
						<a class="btn btn-round btn-primary btn-sm view-detail" title="$value[name]" href="javascript:;" data-href="{$cloudurl}?mod=dzzmarket&op=ajax&do=view&mid=$value[mid]" >{lang view_detail}</a> 
						<!--{/if}-->
					<!--{/if}-->
					<a href="javascript:;" data-href="{$cloudurl}?mod=dzzmarket&op=ajax&do=view&mid=$value[mid]&refer=$refer" class="view-detail btn btn-link" title="$value[name]">查看详情</a>
				</div>
			</div>
			<!--{/loop}-->
		</div>
		<!--{else}-->
		<div class="text-center">
			<img src="static/image/common/no_list.png" /><br>
			<span class="lead">抱歉，没有找到相关应用</span>
		</div>
		<!--{/if}-->
		<!--{if $multi}-->
		$multi
		<!--{/if}-->
		</div>
	</div>
</div>
</main>
<div class="modal fade">
  <div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
    <div class="modal-content">
		<div class="modal-header">
			<h4 class="modal-title text-truncate" id="return_create_newdir"></h4>
			<button type="button" class="btn-close" data-dismiss="modal" aria-label="Close"></button>
		</div>
      <div class="modal-body"> </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal" aria-label="Close">{lang close}</button>
      </div>
    </div>
    <!-- /.modal-content --> 
  </div>
  <!-- /.modal-dialog --> 
</div>
<!-- /.modal -->
<script type="text/javascript">
	jQuery('.view-detail').on('click',function(){
		showBuyInfo(this,'modal-lg');
		return false;
	});
	var ajaxurl='{$cloudurl}';
	function showBuyInfo(obj,size){
		var url=jQuery(obj).data('href');
		var title=jQuery(obj).attr('title');
		if(size){
			jQuery('.modal .modal-dialog').addClass(size);
		}
		jQuery.get(url,function(html){
			html=html.replace(/src=\"index\.php/ig,'src="$cloudurl');
			jQuery('.modal .modal-body').html(html);
		});
		jQuery('.modal .modal-title').html(title);
		jQuery('.modal').modal('show');
	}
	function getNext(url){
		jQuery.get(url,function(html){
			var li=jQuery('.appitem-next');
			li.replaceWith(html);
		});
	}

	function start_check_install(url,mid,data){ 
		jQuery.ajax({
				type:'post',
				async: true, 
				url:url,
				data:{"baseinfo":data },
				success:function(json){
						//jQuery('#install_button_'+mid).html("&nbsp;");  
						if(json.status==0){
							jQuery('#upgrade_info_'+mid).show().addClass("btn-warning").html(json.msg); 
						}else if(json.status==1){ 
							jQuery('#upgrade_info_'+mid).show().text(json.msg);
							jQuery('#upgrade_progess_'+mid).show().animate({width:json.percent+"%"},json.second,function(){
								startinstsallapp(json.url,mid,data);
							});
						}else{
							window.location.reload();
						}
				},
				error: function(xhr, status, error) {
					showmessage('Request failed:' + status +' ' +error, 'error', 3000, 1);
				}
		});
	}

	function startinstsallapp(url,mid,data){
		jQuery.ajax({
			type:'post',
			async: true, 
			url:url,
			data:{"baseinfo":data},
			success:function(json){
				if(json.status==0){
					jQuery('#upgrade_info_'+mid).addClass("btn-warning").html(json.msg);
				}else{
					jQuery('#upgrade_info_'+mid).text(json.msg);
					jQuery('#upgrade_progess_'+mid).animate({width:json.percent+"%"},json.second,function(){
						startgetinstallcrossorpatchfile(json.url,mid,data);
					});
				}
			},
			error: function(xhr, status, error) {
				showmessage('Request failed:' + status +' ' +error, 'error', 3000, 1);
			}
		});
	}

	function startgetinstallcrossorpatchfile(url,mid,data){
		jQuery.ajax({
			type:'post',
			async: true, 
			url:url,
			data:{"baseinfo":data},
			success:function(json){
				if(json.status==0){ 
					jQuery('#upgrade_info_'+mid).addClass("btn-warning").html(json.msg); 
				}else{
					jQuery('#upgrade_info_'+mid).text(json.msg);
					jQuery('#upgrade_progess_'+mid).animate({width:json.percent+"%"},json.second,function(){
						if(json.step==2){
							startgetinstallcrossorpatchfile(json.url,mid,data);
						}else{ 
							startinstallfile(json.url,mid,data);
						}
					}); 
				}
			},
			error: function(xhr, status, error) {
				showmessage('Request failed:' + status +' ' +error, 'error', 3000, 1);
			}
		});
	}

	function startinstallfile(url,mid,data){
		jQuery.ajax({
			type:'post',
			async: true, 
			url:url,
			data:{"baseinfo":data},
			success:function(json){
				if(json.status==0){ 
					jQuery('#upgrade_info_'+mid).addClass("btn-warning").html(json.msg); 
				}else{
					jQuery('#upgrade_info_'+mid).text(json.msg);
					jQuery('#upgrade_progess_'+mid).animate({width:json.percent+"%"},json.second,function(){
						 if(json.step!=5){
							startinstallfile(json.url,mid,data);
						}else{ 
							installover(json.url,mid,data);
						}
					}); 
				}
			},
			error: function(xhr, status, error) {
				showmessage('Request failed:' + status +' ' +error, 'error', 3000, 1);
			}
		});
	}

	function installover(url,mid,data){
		jQuery.ajax({
			type:'post',
			async: true, 
			url:url,
			data:{"baseinfo":data},
			success:function(json){ 
				if(json.status==0){ 
					jQuery('#upgrade_info_'+mid).addClass("btn-warning").html(json.msg); 
				}else{
					jQuery('#upgrade_info_'+mid).text(json.msg);
					jQuery('#upgrade_progess_'+mid).css("width","100%");
				}
			},
			error: function(xhr, status, error) {
				showmessage('Request failed:' + status +' ' +error, 'error', 3000, 1);
			}
		});
	}

	function start_check_upgrade(url,mid){
		jQuery.ajax({
			type:'post',
			async: true, 
			url:url,
			data:{},
			success:function(json){
				jQuery('#upgrade_button_'+mid).html("&nbsp;");  
				if(json.status==0){
					jQuery('#upgrade_info_'+mid).show().text(json.msg);  
				}else{ 
					jQuery('#upgrade_info_'+mid).show().text(json.msg);
					jQuery('#upgrade_progess_'+mid).show().animate({width:json.percent+"%"},json.second,function(){
					startupgrade(json.url,mid);
					});
				}
			},
			error: function(xhr, status, error) {
				showmessage('Request failed:' + status +' ' +error, 'error', 3000, 1);
			}
		});
	}

	function startupgrade(url,mid){
		jQuery.ajax({
			type:'post',
			async: true, 
			url:url,
			data:{},
			success:function(json){ 
				if(json.status==0){
					jQuery('#upgrade_info_'+mid).text(json.msg); 
				}else{
					jQuery('#upgrade_info_'+mid).text(json.msg);
					jQuery('#upgrade_progess_'+mid).animate({width:json.percent+"%"},json.second,function(){
						startgetcrossorpatchfile(json.url,mid);
					});
				}
			},
			error: function(xhr, status, error) {
				showmessage('Request failed:' + status +' ' +error, 'error', 3000, 1);
			}
		});
	}

	function startgetcrossorpatchfile(url,mid){
		jQuery.ajax({
			type:'post',
			async: true, 
			url:url,
			data:{},
			success:function(json){
				if(json.status==0){ 
					alert( json.msg);
				}else{
					jQuery('#upgrade_info_'+mid).text(json.msg);
					jQuery('#upgrade_progess_'+mid).animate({width:json.percent+"%"},json.second,function(){
						if(json.step==2){
							startgetcrossorpatchfile(json.url,mid);
						}else{
							startupgradefile(json.url,mid);
						}
					}); 
				}
			},
			error: function(xhr, status, error) {
				showmessage('Request failed:' + status +' ' +error, 'error', 3000, 1);
			}
		});
	}

	function startupgradefile(url,mid){
		jQuery.ajax({
			type:'post',
			async: true, 
			url:url,
			data:{},
			success:function(json){ 
				if(json.status==0){ 
					alert( json.msg);
				}else{
					jQuery('#upgrade_info_'+mid).text(json.msg);
					jQuery('#upgrade_progess_'+mid).animate({width:json.percent+"%"},json.second,function(){
						 if(json.step!=5){
							startupgradefile(json.url,mid);
						}else{
							upgradeover(json.url,mid);
						}
					}); 
				}
			},
			error: function(xhr, status, error) {
				showmessage('Request failed:' + status +' ' +error, 'error', 3000, 1);
			}
		});
	}

	function upgradeover(url,mid){
		jQuery.ajax({
			type:'post',
			async: true, 
			url:url,
			data:{},
			success:function(json){
				if(json.status==0){ 
					alert( json.msg);
				}else{
					jQuery('#upgrade_progess_'+mid).animate({width:"100%"},300,function(){
						jQuery('#upgrade_progess_'+mid).hide().css("width","0");
						start_check_upgrade(json.url,mid);
					}); 
				}
			},
			error: function(xhr, status, error) {
				showmessage('Request failed:' + status +' ' +error, 'error', 3000, 1);
			}
		});
	} 
		
</script> 
<!--{template lyear:footer_simple}-->